﻿// Type: trx2html.Parser.TestRunResult
// Assembly: RidoTasks, Version=0.7.3.1523, Culture=neutral, PublicKeyToken=null
// Assembly location: C:\Users\jigar\Desktop\Vinay\trx2html_0.7\0.7.3\RidoTasks.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace trx2html
{
  internal class TestRunResult : I3ValueBar
  {
    public IEnumerable<TestMethodRun> TestMethodRunList;
    public List<TestClassRun> TestClassList;

    public string RunInfo { get; set; }

    public int TotalMethods
    {
      get
      {
        return Enumerable.Count<TestMethodRun>(this.TestMethodRunList);
      }
    }

    public IEnumerable<string> Computers
    {
      get
      {
        return Enumerable.Distinct<string>(Enumerable.Select<TestMethodRun, string>(this.TestMethodRunList, (Func<TestMethodRun, string>) (t => t.ComputerName)));
      }
    }

    public int Passed
    {
      get
      {
        return Enumerable.Count<TestMethodRun>(Enumerable.Where<TestMethodRun>(this.TestMethodRunList, (Func<TestMethodRun, bool>) (t => t.Status == "Passed")));
      }
    }

    public int Failed
    {
      get
      {
        return Enumerable.Count<TestMethodRun>(Enumerable.Where<TestMethodRun>(this.TestMethodRunList, (Func<TestMethodRun, bool>) (t => t.Status == "Failed")));
      }
    }

    public int Inconclusive
    {
      get
      {
        return Enumerable.Count<TestMethodRun>(Enumerable.Where<TestMethodRun>(this.TestMethodRunList, (Func<TestMethodRun, bool>) (t =>
        {
          if (!(t.Status == "Inconclusive") && !(t.Status == "NotRunnable"))
            return t.Status == "Aborted";
          else
            return true;
        })));
      }
    }

    public double TotalPercent
    {
      get
      {
        if (this.TestClassList.Count > 0)
          return Math.Round(Enumerable.Average<TestClassRun>((IEnumerable<TestClassRun>) this.TestClassList, (Func<TestClassRun, double>) (c => c.Percent)));
        else
          return 0.0;
      }
    }

    public double PercentOK
    {
      get
      {
        return Math.Round(100.0 * ((double) this.Passed / (double) this.TotalMethods), 0);
      }
    }

    public double PercentKO
    {
      get
      {
        return Math.Round(100.0 * ((double) this.Failed / (double) this.TotalMethods), 0);
      }
    }

    public double PercentIgnored
    {
      get
      {
        return Math.Round(100.0 * ((double) this.Inconclusive / (double) this.TotalMethods), 0);
      }
    }

    public TimeSpan TimeTaken
    {
      get
      {
        return TimeSpan.FromTicks(Enumerable.Sum<TestClassRun>((IEnumerable<TestClassRun>) this.TestClassList, (Func<TestClassRun, long>) (c => c.Duration.Ticks)));
      }
    }

    public string Name { get; set; }

    public IEnumerable<AssemblyName> Assemblies
    {
      get
      {
        return Enumerable.Distinct<AssemblyName>(Enumerable.Select<TestClassRun, AssemblyName>((IEnumerable<TestClassRun>) this.TestClassList, (Func<TestClassRun, AssemblyName>) (c => c.AssemblyName)), (IEqualityComparer<AssemblyName>) new AssemblyNameComparer());
      }
    }

    public string UserName { get; set; }

    public IEnumerable<TestMethodRun> TopSlowerMethods
    {
      get
      {
        return Enumerable.Take<TestMethodRun>((IEnumerable<TestMethodRun>) Enumerable.OrderByDescending<TestMethodRun, TimeSpan>(this.TestMethodRunList, (Func<TestMethodRun, TimeSpan>) (m => m.Duration)), 5);
      }
    }

    public TestRunResult(string name, string runUser, IEnumerable<TestMethodRun> items)
    {
      this.Name = name;
      this.UserName = runUser;
      this.TestMethodRunList = (IEnumerable<TestMethodRun>) new List<TestMethodRun>(items);
      this.TestClassList = new List<TestClassRun>();
      foreach (string str in Enumerable.Select<TestMethodRun, string>(Enumerable.Distinct<TestMethodRun>(this.TestMethodRunList, (IEqualityComparer<TestMethodRun>) new TestMethodRun()), (Func<TestMethodRun, string>) (t => t.TestClass)))
      {
        string c = str;
        this.TestClassList.Add(new TestClassRun(c, Enumerable.Select<TestMethodRun, TestMethodRun>(Enumerable.Where<TestMethodRun>(items, (Func<TestMethodRun, bool>) (t => t.TestClass == c)), (Func<TestMethodRun, TestMethodRun>) (t => t))));
      }
    }
  }
}
